package com.hfh.test;

import java.util.Arrays;

/**
 * @Author hfh
 * @Date 2022 09 15 10 26
 **/
public class BubbleSort{
    public static void main(String[] args) {
        int[] arr = {8,5,6,1,2,3,4,7};
        sort(arr);
        for (int i : arr){
            System.out.print(i+" ");
        }
    }


    public static int[] sort(int[] arr){
        for (int i = 1; i < arr.length; i++) {
            boolean flag = true;

            for (int j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;

                    flag = false;
                }
            }

            if (flag) {
                break;
            }
        }
        return arr;
    }
}
